<template>
    <el-form ref="ruleFormRef" label-position="top" :model="importForm" :rules="formRules" label-width="auto"
        v-loading="isLoading">
        <el-row :gutter="30">
            <re-col :value='24' :xs='24' :sm='24'>
                <el-form-item prop='file'>
                    <el-upload class="upload-demo" drag action="" :auto-upload="false" multiple :limit="1"
                        :style="{ width: '100%' }" :on-change="handleChange" v-model:file-list="uploadFiles">
                        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
                        <div class="el-upload__text">
                            拖拽文件或者<em>点击文件</em>上传
                        </div>
                        <template #tip>
                            <div class="el-upload__tip">
                                <!-- jpg/png files with a size less than 500kb -->
                            </div>
                        </template>
                    </el-upload>
                </el-form-item>
            </re-col>
            <!-- <re-col :value='12' :xs='24' :sm='24'>
                <el-form-item :label='titles?.operator' prop='operator'>
                    <operatorSelect v-model='importForm.operator' clearable :placeholder='prompt?.operator'
                        :style="{ width: '100%' }" @blur="formValidateField(ruleFormRef, 'operator')"></operatorSelect>
                </el-form-item>
            </re-col>
            <re-col :value='12' :xs='24' :sm='24'>
                <el-form-item :label='titles?.canal' prop='canal'>
                    <canalSelect v-model='importForm.canal' clearable :placeholder='prompt?.canal'
                        :style="{ width: '100%' }" @blur="formValidateField(ruleFormRef, 'canal')">
                    </canalSelect>
                </el-form-item>
            </re-col>
            <re-col :value='12' :xs='24' :sm='24'>
                <el-form-item :label='titles?.expireDate' prop='expireDate'>
                    <el-date-picker v-model='importForm.expireDate' clearable :placeholder='prompt?.expireDate'
                        format="YYYY/MM/DD" value-format="YYYY-MM-DD" :style="{ width: '100%' }" />
                </el-form-item>
            </re-col>
            <re-col :value='12' :xs='24' :sm='24'>
                <el-form-item :label='titles?.unityId' prop='unityId'>
                    <unitParentSelect v-model='importForm.unityId' clearable :placeholder='prompt?.unityId'
                        :style="{ width: '100%' }" @blur="formValidateField(ruleFormRef, 'unityId')"/>
                </el-form-item>
            </re-col> -->
        </el-row>
    </el-form>
</template>
<script lang="ts" setup>
import { UploadFilled } from '@element-plus/icons-vue';
import ReCol from "@/components/ReCol";
import operatorSelect from '@/components/select/operatorSelect/operatorSelect.vue'
import canalSelect from '@/components/select/canalSelect/canalSelect.vue'
import unitParentSelect from '@/components/select/unitParentSelect/unitParentSelectTree.vue'
import type { FormRules } from "element-plus";
import { titles, prompt } from './index';
import { formValidateField } from '@/utils/functions'
type FormProps = {
    importForm: any,
    isLoading: false
}
const props = withDefaults(defineProps<FormProps>(), {
    importForm: {
        file: null,
        operator: null,
        canal: null,
    },
    isLoading: false
});

const ruleFormRef = ref();
const formRules = reactive(<FormRules>{
    file: [{ required: true, message: '请选择导入文件', trigger: 'blur' },],
    operator: [{ required: true, message: prompt?.operator, trigger: 'blur' },],
    canal: [{ required: true, message: prompt?.canal, trigger: 'blur' },],
    expireDate: [{ required: true, message: prompt?.expireDate, trigger: 'blur' },],
    unityId: [{ required: true, message: prompt?.unityId, trigger: 'blur' },],
});
const uploadFiles = ref<any>([])
const handleChange = (uploadFile, uploadFiles) => {
    props.importForm.file = uploadFile.raw
}




function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>
<style lang="scss" scoped></style>